﻿@model RH.Web.ViewModels.ServicePeriodSpanViewModel
@using RH.Web.Utility;
@using RH.Web.ViewModels;
@using RH.Common.Extensions;

@{
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
	String pageTitle = "Edit Service Period Span";
    if (Model != null && Model.ID == 0)
    {             
        pageTitle = "Add New ServicePeriodSpan";
    }
    ViewBag.Title = Html.GetPageTitle(pageTitle);
	//ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = CompanyMenu.Dashboard;
	bool _HasSaved = RH.Common.DB.NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SAVED]);
}

<div class="rh-page-heading">
    <h1>@pageTitle</h1>
    <div>You can edit only committed lead per span, other information are read only.</div>
</div>
<div class="rh-page-content">
@if (Model == null || Model.ID <= 0) {
    @: @Html.WarningMessageBox("Sorry! Invalid Request")
} else { 
    using (Html.BeginForm()) {
        @Html.ValidationSummary(false)

	    if (Model == null)
        {
            @: @Html.WarningMessageBox("Sorry! Requested Service Period Span was not found for edit.")
        }
	    else
	    {
		    if (_HasSaved) {
                @Html.SuccessMessageBox("Congratulations! The Service Period Span saved successfully")
                
            }
            else if (ViewData[AppConstants.ViewDataKeys.SAVED] != null && !_HasSaved)
            {
                @Html.WarningMessageBox("Sorry! we could not save the Service Period Span.")
            }
		    @Html.HiddenFor(model => model.ID)
            @Html.HiddenFor(model => model.ServicePeriodID)
            @Html.HiddenFor(model => model.LeadSent)
            @Html.HiddenFor(model => model.IsDeleted)
            @Html.Hidden("hdnSaveIndicator", _HasSaved)
		    <div class="editor-label">
			    @Html.LabelFor(model => model.StartDate)
		    </div>
		    <div class="editor-field">
			    @Model.StartDate.ToDateTime(ConfigReader.CSharpCalendarDateFormat).ToString(AppConstants.ValueOf.DATE_FROMAT_DISPLAY)
                @Html.HiddenFor(model => model.StartDate)
		    </div>
		    <div class="editor-label">
                @Html.LabelFor(model => model.EndDate)
		    </div>
		    <div class="editor-field">
			    @Model.EndDate.ToDateTime(ConfigReader.CSharpCalendarDateFormat).ToString(AppConstants.ValueOf.DATE_FROMAT_DISPLAY)
			    @Html.HiddenFor(model => model.EndDate)
		    </div>
		    <div class="editor-label">
			    @Html.LabelFor(model => model.LeadPerSpan)
		    </div>
		    <div class="editor-field">
			    @Html.TextBoxFor(model => model.LeadPerSpan)
			    @Html.ValidationMessageFor(model => model.LeadPerSpan)
		    </div>
		    <div class="rh-button-container">			
			    <button type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
                @*<a href="@Url.PrivateUrl("List", "Product")" class="btn btn-default"><i class="glyphicon glyphicon-arrow-left"></i> Back to List</a>*@
		    </div>		
	    }
    }
}
</div>
@section PageHeadSection
{
    <style type="text/css">
        label{font-weight:bold;}
    </style>
}
@section JavaScriptPlaceHolder
{
    @Scripts.Render(Bundles.jQueryValidate)
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            if ($('#hdnSaveIndicator').val().toLowerCase() == 'true') {
                parent.ReloadSpanList();
            }
        });
    </script>
}

